package com.cwj.mansysback.entity;

import com.cwj.mansysback.dao.util.MD5Util;
import com.cwj.mansysback.servlet.util.MyUtils;

import java.sql.Timestamp;
import java.util.Date;


public class Account implements SendDone {

    private static final String TABLE_NAME = "account";

    //    Enum<>
    public enum RankName {
        ADMIN(1), TEACHER(2), STUDENT(3);

        Integer rank;

        RankName(int i) {
            this.rank = i;
        }

        public Integer getRank() {
            return rank;
        }

        public void setRank(Integer rank) {
            this.rank = rank;
        }
    }

    private String aid;
    private String pawd; //加密后的密码
    private String password;//未加密
    private Integer accrank;
    private String avater;//头像

    public void setPawd(String pawd) {
        this.pawd = pawd;
    }

    public String getAvater() {
        return avater;
    }

    public void setAvater(String avater) {
        this.avater = avater;
    }


    public Account(String aid, String password, Integer accrank) {
        this.aid = aid;
        this.setPassword(password);
        this.accrank = accrank;
    }

    public Account() {
//        this.aid=this.avater=this.password=this.pawd="";
    }

    public String getAid() {
        return aid;
    }

    public String getPawd() {
        if(this.password != null)   return this.pawd = MD5Util.encode(this.password);
        else return pawd;
    }

    public Integer getAccrank() {
        return accrank;
    }

    public void setAid(String aid) {
        this.aid = aid;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
//        this.pawd = MD5Util.encode(this.password);
    }

    public void setAccrank(Integer accrank) {
        this.accrank = accrank;
    }

    public static String getTableName() {
        return TABLE_NAME;
    }

    @Override
    public void init() {

    }
    @Override
    public void lastChange(){
        this.setPassword(null);
        this.setPawd(null);
    }



    @Override
    public String toString() {
        return "Account{" +
                "aid='" + aid + '\'' +
                ", pawd='" + pawd + '\'' +
                ", password='" + password + '\'' +
                ", accrank=" + accrank +
                ", avater='" + avater + '\'' +
                '}';
    }
}
